package edu.je.column.controller;

import com.junqson.je.common.UserHolder;
import com.junqson.je.common.annotation.LoginRequire;
import com.junqson.je.common.model.ApiResult;
import edu.je.column.model.ColumnModel;
import edu.je.column.model.NewsModel;
import edu.je.column.model.SubscribeStateModel;
import edu.je.column.model.Vo.ColumnVo;
import edu.je.column.model.Vo.ColumnWithoutContentVo;
import edu.je.column.service.ColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author MengXin
 * @description:
 * @program: je-gateway
 * @date 2021/4/22 3:08
 * @mail mx@radish.cloud
 */

@RestController
@RequestMapping("column")
public class ColumnController {

    @Autowired
    ColumnService columnService;

    /**
     * @param page
	 * @param size
     * @return com.junqson.je.common.model.ApiResult
     * @author Mengxin
     * @describe:
     * @date 2021/4/22 19:45
     */
    @RequestMapping("getColumnList")
    public ApiResult getColumnList(@RequestParam(required = false) Integer page,
                                   @RequestParam(required = false) Integer size,
                                   @RequestParam(required = false) String section){
        List<ColumnWithoutContentVo> models = columnService.getColmunList(page,size,section);
        return ApiResult.success(models);
    }

    /**
     * @param columnId
     * @return com.junqson.je.common.model.ApiResult
     * @author Mengxin
     * @describe:
     * @date 2021/4/23 2:57
     */
    @RequestMapping("getColumnDetailById")
    public ApiResult getColumnDetailById(@RequestParam(required = false) Long columnId){
        ColumnVo model = columnService.getColumnDetailById(columnId);
        return ApiResult.success(model);
    }

    /**
     * @param columnId
     * @return com.junqson.je.common.model.ApiResult
     * @author Mengxin
     * @describe:
     * @date 2021/4/23 2:57
     */
    @LoginRequire
    @RequestMapping("getSubscribeStateById")
    public ApiResult getSubscribeStateById(@RequestParam(required = false) Long columnId){
        Integer userId = UserHolder.get().getUserId();
        Integer model = columnService.getSubscribeStateById((long)userId,columnId);
        return ApiResult.success(model);
    }

    /**
     * @param columnId
     * @return com.junqson.je.common.model.ApiResult
     * @author Mengxin
     * @describe:
     * @date 2021/4/23 2:57
     */
    @LoginRequire
    @RequestMapping("subscribColumnById")
    public ApiResult subscribColumnById(@RequestParam(required = false) Long columnId){
        Integer userId = UserHolder.get().getUserId();
        SubscribeStateModel models = columnService.subscribColumnById((long)userId,columnId);
        return ApiResult.success(models);
    }



}
